package org.monklypse.jme2.demoapp.views;


import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.jme.system.canvas.JMECanvasImplementor;

/**
 * A simple composite to show fps
 * 
 * @author Tareq doufish
 */
public class SimpleStatesComposite extends Composite implements Updatable {
	
	private JMECanvasImplementor implementor;
	
	private Label label;
	private Text statesLabel;
	
	public SimpleStatesComposite(Composite parent, JMECanvasImplementor implementor) {
		super(parent, SWT.NONE);
		this.implementor = implementor;
		
		setLayout(new GridLayout(2, false));
		
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.heightHint = 20;
		this.setLayoutData(data);
		
		label = new Label(this, SWT.NONE);
		label.setText("FPS: ");
		
		statesLabel = new Text(this, SWT.BORDER);
		statesLabel.setText("");
		statesLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		((DemoImplementor)implementor).addUpdatable(listener);
	}
	
	public void updateFPSLabel() {
		
	}
	
	private Updatable listener = new Updatable() {
		public void update() {
			if (statesLabel.isDisposed())
				return;
			statesLabel.setText(((DemoImplementor)implementor).getFPS() + "");
		}
	};
}
